CC=gcc

PIDGIN_CFLAGS=`pkg-config --cflags pidgin purple`
PIDGIN_LIBS=`pkg-config --libs pidgin purple`
PIDGIN_PREFIX=`pkg-config --variable=prefix purple`

GTK_CFLAGS = `pkg-config --cflags gtk+-2.0`
GTK_LIBS=`pkg-config --libs gtk+-2.0`

GOBJECT_CFLAGS=`pkg-config --cflags gobject-2.0`
GOBJECT_LIBS=`pkg-config --libs gobject-2.0 gmodule-2.0`


MSN_LIB="$(PIDGIN_PREFIX)/lib/purple-2/libmsn.so"
JABBER_LIB="$(PIDGIN_PREFIX)/lib/purple-2/libjabber.so"
MSN_PECAN_LIB="$(PIDGIN_PREFIX)/lib/purple-2/libmsn-pecan.so"

PREFIX=$(DESTDIR)/$(PIDGIN_PREFIX)
plugin_dir=$(PREFIX)/lib/purple-2
data_dir=$(prefix)/share

# For simple output
P = @printf "[%s] $@\n" # <- space before hash is important!!!
Q = @

CFLAGS+=-O2 -Wall
#LDFLAGS:=-Wl,--no-undefined

ifdef DEBUG
CFLAGS+=-ggdb
endif

SHLIBEXT=so
ifdef STATIC
	plugin=personalbar.a
	#override CFLAGS += -DPURPLE_STATIC_PRPL
else
	plugin=personalbar.$(SHLIBEXT)
	override CFLAGS += -fPIC
endif

.PHONY: all clean

objects = personalbar.o

all: $(plugin)

$(plugin): $(objects)
$(plugin): CFLAGS := $(CFLAGS) $(PIDGIN_CFLAGS) \
							$(GOBJECT_CFLAGS) $(GTK_CFLAGS) \
							$(MSN_CFLAGS) $(INTERNAL_CFLAGS) \
							"-DMSN_LIB=\"$(MSN_LIB)\"" \
							"-DJABBER_LIB=\"$(JABBER_LIB)\"" \
							"-DMSN_PECAN_LIB=\"$(MSN_PECAN_LIB)\""

$(plugin): LIBS := $(PIDGIN_LIBS) $(GTK_LIBS) \
							$(GOBJECT_LIBS) $(MSN_LIBS) \
							$(MSN_PECAN_LIBS) $(JABBER_LIBS)

# $(P)CC shows [CC] and the next line shows the nice output
%.o:: %.c
	$(P)CC
	$(Q)$(CC) $(CFLAGS) -Wp,-MMD,$(dir $@).$(notdir $@).d -o $@ -c $<

# Make the shared object/lib
%.so::
	$(P)SHLIB
	$(Q)$(CC) -shared -o $@ $^ $(LIBS)  

clean: 
	rm -f $(plugin) $(objects)

install: $(plugin)
	mkdir -p $(plugin_dir)
	install $(plugin) $(plugin_dir)
	
uninstall:
	rm $(PIDGIN_PREFIX)/lib/purple-2/personalbar.so
